Getting started with the analysis of nvg data

This notebook assumes that data exists in a database in the hdf5 format. For instructions how to set up the database with data see [../readme.md].

Import modules


In [1]:
import numpy as np
import matplotlib.pyplot as plt
import nvg.ximu.ximudata as ximudata
%matplotlib notebook

Load the database


In [2]:
reload(ximudata)
dbfilename = "/home/kjartan/Dropbox/Public/nvg201209.hdf5"
db = ximudata.NVGData(dbfilename);

Explore contents of the database file


In [3]:
dbfile = db.hdfFile;
print "Subjects: ",  dbfile.keys()
print "Trials: ", dbfile['S5'].keys()
print "IMUs: ", dbfile['S5/B'].keys()
print "Attributes of example trial", dbfile['S5/B'].attrs.keys()
print "Shape of example IMU data entry", dbfile['S5/B/N'].shape


Subjects:  [u'S10', u'S11', u'S12', u'S2', u'S3', u'S4', u'S5', u'S6', u'S7', u'S8', u'S9']
Trials:  [u'B', u'D', u'M', u'N']
IMUs:  [u'B', u'LA', u'LH', u'LT', u'N', u'RA', u'RH', u'RT']
Attributes of example trial [u'PNAtICLA', u'PNAtICRA', u'PNAtCycleEvents', u'cycleFrequency', u'verticalDisplacement']
Shape of example IMU data entry (87243, 10)

The content of the raw IMU file

The columns of the IMU data contain: 0: Packet number, 1: Gyroscope X (deg/s), 2: Gyroscope Y (deg/s), 3: Gyroscope Z (deg/s), 4: Accelerometer X (g), 5: Accelerometer Y (g), 6: Accelerometer Z (g), 7: Magnetometer X (G), 8: Magnetometer Y (G), 9: Magnetometer Z (G)

Plot example data


In [4]:
db.plot_imu_data()


Out[4]:
<HDF5 dataset "N": shape (87250, 10), type "<f8">

Implemented analysis methods


In [7]:
print [s for s in dir(db) if s.startswith("get")]


['get_PN_at_sync', 'get_ROM_joint_angle', 'get_RoM_angle_to_vertical', 'get_angle_between_segments', 'get_angle_to_vertical', 'get_cycle_data', 'get_cycle_frequency', 'get_imu_data', 'get_minmax_angle_to_vertical', 'get_minmax_joint_angle', 'get_orientation', 'get_range_of_motion', 'get_trial_attribute', 'get_vertical_displacement']

Try an analysis


In [8]:
res = db.apply_to_all_trials(db.get_RoM_angle_to_vertical, {'imu':'N'},
                                           subjlist=['S2', 'S3'], triallist=['B', 'N'])


-----------------------------------------
Applying function to subject S2
Applying to trial B
Applying to trial N
-----------------------------------------
-----------------------------------------
Applying function to subject S3
Applying to trial B
Applying to trial N
-----------------------------------------

In [9]:
res


Out[9]:
{(u'S2', u'B'): [3.1110409014255467,
  2.9438168105871036,
  3.5368140796090222,
  3.1687908382598735,
  5.1064980360923808,
  4.9021110623806186,
  2.7195431045088161,
  4.8422110519965536,
  4.946002701060384,
  5.1986265996160181,
  4.9753839021251469,
  2.9927959174079803,
  3.9671171087898114,
  5.0429188137576002,
  4.9954715322755545,
  2.9732938597584915,
  6.1155100624376635,
  4.2127798988126326,
  3.2300125581052908,
  3.1680386490155752,
  5.7109535612199069,
  3.0395015349100425,
  3.3143980074652077,
  3.899944844069636,
  3.0861349019567799,
  3.9736807411326605,
  5.3552836185804198,
  4.5232490672489014,
  5.2461225209894042,
  2.3197414188633387,
  4.4291984556839887,
  3.5978049521994135,
  2.5535898704619897,
  3.6412909380591856,
  3.0741175790576274,
  4.5682937021418066,
  4.8607086124395282,
  5.2046313245354474,
  2.6614973183774469,
  4.2157420129181213,
  4.463370974871653,
  4.8473057353747588,
  4.0023072969483264,
  3.5634191055024851,
  3.6491750452186298,
  3.9035939215010265,
  3.545029639320183,
  5.4588055387388961,
  5.1573503697459602,
  3.9921942552544976,
  5.2711048564911342,
  3.1175705581097648,
  4.063179968508245,
  3.3281027369408571],
 (u'S2', u'N'): [10.461771074020948,
  19.499041723717319,
  17.293932622187981,
  4.6571198184931228,
  5.2707602990792379,
  5.1170143111813031,
  9.7887543959546939,
  7.1408442836852117,
  6.9743319429455219,
  4.632175763395737,
  4.4956362392446252,
  4.1112869011795308,
  4.6703277833196424,
  5.2337726133295224,
  4.4266424155923341,
  5.4997803253816979,
  3.8649078372336563,
  4.381573908487038,
  5.0116843409036411,
  3.8064699163185161,
  5.7471127077886299,
  4.7154422562247706,
  3.9047323443194344,
  4.0832992810694986,
  6.2843037329518019,
  4.1855814899766433,
  4.8303992167270584,
  4.5640098615985032,
  5.3364085021899967,
  6.8928864040842068,
  3.3251366206506829,
  5.5521761300906007,
  2.9557991542110083,
  5.2722894287639201,
  4.2230215734083929,
  2.9031657672415601,
  4.3012511717865953,
  3.5151589349230457,
  3.5399270043241633,
  4.5472719673572426,
  6.1231430632187083,
  5.1119042036246656,
  3.0800208684361223,
  3.8879148799661856,
  5.1130315440269758,
  6.1199393348457427,
  2.5489895679849806,
  3.1747770751182198,
  2.7405739683322148,
  5.6955049713915065,
  4.6574568509829746,
  3.8975799616231286,
  6.5605771512777906,
  4.3584464924645143],
 (u'S3', u'B'): [10.468333835872404,
  7.2020543489435358,
  9.1305144903088777,
  8.2034144153042252,
  5.8264467839584411,
  8.4031020655845499,
  6.4373150590135646,
  8.3025594073485234,
  7.3689430307841732,
  7.0147492750399971,
  7.9841813567786852,
  6.4181476501092956,
  8.8717330592009542,
  6.210939058283981,
  5.1668335462464574,
  7.8112317505658826,
  7.2726330030401689,
  11.567040933962394,
  6.1780401508222047,
  9.4477317761869646,
  8.7036070675553319,
  8.4608872909616668,
  8.2896634324404026,
  7.3615282486989164,
  8.3356580432863119,
  7.3344636378783354,
  7.6789610677191265,
  7.1481535190495746,
  6.6376418884946702,
  8.6481333298704168,
  8.6041375059551406,
  7.1430414419634838,
  8.9645926821767876,
  6.9742548674534017,
  8.260037815273666,
  7.1893579784408983,
  9.083657612886638,
  10.823239897779073,
  9.971382675730867,
  8.7235985643881513,
  7.9602673044743701,
  6.7500667361190336,
  8.2899503456365178,
  8.2552687242754725,
  6.9475703298397944,
  6.5398251500037343,
  9.5911998988027722,
  7.018495272681327,
  8.5853238609008553,
  7.0802181136807008,
  8.3487117282307963],
 (u'S3', u'N'): [8.188991047936991,
  6.0084564852564455,
  7.8164352476467061,
  8.1881715012195482,
  9.0700703188810952,
  8.8093130654577294,
  6.8078937549361003,
  9.1313362223642205,
  9.3924714364630937,
  9.6237992544259416,
  8.3728260683985098,
  8.1992981114392194,
  8.199176248075867,
  8.7378601292008664,
  9.7350925709821308,
  7.7999314506861817,
  8.5648101730402875,
  7.2255504542128905,
  7.2457258946290724,
  6.912723647932375,
  9.8117823291015078,
  7.2058146700881593,
  6.6524566085843615,
  7.9905120458933467,
  8.4995474060465366,
  7.3602285677674919,
  5.3241167682292314,
  8.293312496120306,
  7.999556999544537,
  9.0687049926932435,
  6.9967093791514587,
  7.2120735726505059,
  9.4718901590582103,
  9.0019809861378484,
  8.4632522214463854,
  11.473701328863887,
  8.6695437846281038,
  6.4041195356992695,
  8.2526898418256565,
  9.4275025801931243,
  7.5057981740583797,
  7.0963047564477302,
  9.6717565518846094,
  9.9744516000021246,
  4.2340516326047446,
  6.4656683538900621,
  6.5090984050803655,
  6.0018823642573693,
  6.8309993902197919,
  7.8941816819683286,
  6.5614391174610613]}

In [ ]: